#!/bin/bash
#THIS DRIVER WRITTEN BY MATTHEW VONA ARB FOR THE API Picarro G2301
#FOR QUESTIONS WRITE mailto:mvona@arb.ca.gov
#UPDATE: 08/22/2014;
#-------------------------------------------------------------
#DIR returns operating directory of the testd script
DIR="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# THIS IS THE FUNCTION CALLED IN THE EVENT THAT CTRL+C IS PRESSED
cleanup()
{
	echo "Caught Signal ... cleaning up."
		if !(rm -f Data/.locked > /dev/null); then
       			{
               		 exit 1
        		} 
		fi
	echo "Done cleanup ... quitting."
	exit 1
}


#This is a TCP driver for the PICARRO
#{ echo "_MEAS_GETBUFFER"; sleep 5 ;} | telnet 146.114.111.121 51020
ip_addr=${1}
port=${2}
while :
do
{ echo "_MEAS_GETBUFFER"; sleep 30 ;} | telnet ${ip_addr} ${port} 2>/dev/null | grep ':' >> ${DIR}/.write_cache
done
